package 力扣链表;

public class Leetcode26原地删除数组中的重复项 {
    public static void main(String[] args) {
        int[] nums = new int[]{0,0,1,1,1,2,2,3,3,4};
        int i = removeDuplicates(nums);
        System.out.println(i);
    }
    public static int removeDuplicates(int[] nums) {
        int left = 0,right = 0;
        while (right < nums.length){
            //如果左边等于不等于右边，左边++，右边++
            if (nums[left] != nums[right]){
                left++;
                nums[left] = nums[right];
            }
            right++;
        }
        return left+1;
    }
    public static int removeDuplicates1(int[] nums) {
        //单指针
        int left = 0,right = 0;
        for (int i = 1; i < nums.length; i++) {
            //如果相邻两元素相等
            if (nums[i] == nums[i-1]){
                continue;
            }else {
                left++;
                nums[left] = nums[i];
            }
        }
        return left+1;
    }
}
